var http = require("http");
const path = require("path");
const fs = require("fs");


var arg = process.argv[2];
if(!arg) arg="fileReader2.js";
var filePath = path.join(__dirname,"/" + arg);

http.createServer((reg,res)=>{
    if(fs.existsSync(filePath)){        
        var fd = fs.openSync(filePath,"r");
        var buf = Buffer.alloc(10);
        var result = fs.readSync(fd,buf);
        // res.write(200,{"Content-Type":"text/html;charset=utf-8"});
        res.end(buf);
        fs.closeSync();  
    }
    else{
        res.end("该路径文件不存在");
    }
}).listen(8081);
